package com.example.kiratest.notify.Test;

import com.alibaba.fastjson.JSON;
import com.example.kiratest.notify.DingtalkNotifier;
import com.example.kiratest.notify.Enum.MsgTypeEnum;
import com.example.kiratest.notify.POJO.CardRequest;
import com.example.kiratest.notify.POJO.DingtalkColumnsItem;
import com.example.kiratest.notify.POJO.DingtalkRowsItem;
import com.example.kiratest.notify.POJO.DingtalkTableItem;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * 简单构造数据向钉钉群聊发送卡片
 */

/**
 * packageName
 * gp商城apk版本
 * 当前apk版本
 * apkcombo apk版本
 */
@Slf4j
public class GetByVersionMain {
    public static void main(String[] args) {

        DingtalkRowsItem dingtalkRowsItem= new DingtalkRowsItem()
                .setOfferId("1")
                .setAffiliateId("1")
                .setPackageName("阮志荣")
                .setCap(300)
                .setPbNumber(80)
                .setTimezone(3000);

        //CardRequest
        CardRequest pbNotifierMsg = pbNotifierMsg();
        //转换成发起请求的对象
        List<DingtalkRowsItem> dingTalkRowsItems = new ArrayList<>();
        dingTalkRowsItems.add(dingtalkRowsItem);
        //构建CardRequest
        pbNotifierMsg.getCardData().getCardParamMap().getTableBean().setData(dingTalkRowsItems);
        DingtalkTableItem tableBean = pbNotifierMsg.getCardData().getCardParamMap().getTableBean();
        pbNotifierMsg.getCardData().getCardParamMap().setTable(JSON.toJSONString(tableBean));
        pbNotifierMsg.setOpenSpaceId(MsgTypeEnum.NOTIFY2.getOpenSpaceId());//群聊场域Id
        pbNotifierMsg.setCardTemplateId("824ef344-4d2d-4b12-9ff9-d86ab943e67c.schema");//卡片模板Id
        pbNotifierMsg.setOutTrackId(UUID.randomUUID().toString());//请求唯一Id

        //将CradRequest对象变成Json字符串
        String jsonString = JSON.toJSONString(pbNotifierMsg);

        DingtalkNotifier dingtalkNotifier = new DingtalkNotifier();

        dingtalkNotifier.notify(jsonString, null);
    }



    /**
     * 我们主要有5个参数 offerId,affilicateId,packageName,cap,pbNumber
     * setAlias是往里面放数据
     * setAliasName是数据展示的时候我们的名字
     */
    public static CardRequest pbNotifierMsg() {
        List<DingtalkColumnsItem> columnsItems = new ArrayList<>();
        columnsItems.add(new DingtalkColumnsItem().setDataType("STRING")
                .setAlias("offerId").setAliasName("offerId").setWeight(20));
        columnsItems.add(new DingtalkColumnsItem().setDataType("STRING")
                .setAlias("affiliateId").setAliasName("affiliateId").setWeight(20));
        columnsItems.add(new DingtalkColumnsItem().setDataType("STRING")
                .setAlias("packageName").setAliasName("packageName").setWeight(20));
        columnsItems.add(new DingtalkColumnsItem().setDataType("STRING")
                .setAlias("cap").setAliasName("cap数").setWeight(20));
        columnsItems.add(new DingtalkColumnsItem().setDataType("STRING")
                .setAlias("pbNumber").setAliasName("上游转化数").setWeight(20));
        columnsItems.add(new DingtalkColumnsItem().setDataType("STRING")
                .setAlias("number").setAliasName("测试变量").setWeight(20));
        return new CardRequest("offer监控通知", columnsItems);
    }

}
